package logic

import (
	"context"
	"zf/models/mysql"

	"zf/zfrpc/internal/svc"
	"zf/zfrpc/zfrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodCarAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodCarAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodCarAddLogic {
	return &GoodCarAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodCarAddLogic) GoodCarAdd(in *zfrpc.GoodCarAddRequest) (*zfrpc.GoodCarAddResponse, error) {
	// todo: add your logic here and delete this line
	goodCar := mysql.GoodCar{
		GoodHomeId:   int(in.GoodId),
		GoodId:       int(in.GoodId),
		GoodHomeName: in.GoodHomeName,
		GoodName:     in.GoodName,
		Num:          int(in.Num),
		Price:        float64(in.Price),
	}

	mysql.DB.Debug().Create(&goodCar)

	return &zfrpc.GoodCarAddResponse{
		GoodCarId: int64(goodCar.ID),
	}, nil
}
